package com.lazy.netty.ex.basic;

import java.io.IOException;

import com.google.protobuf.CodedOutputStream;
import com.lazy.lib.util.ByteUtil;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;

public class CodedStreamDemo {

    public static void main(String[] args) throws IOException{
        ByteBuf out = Unpooled.buffer();
        int bodyLen = 30000;
        int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
        out.ensureWritable(headerLen + bodyLen);

        CodedOutputStream headerOut =
                CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
        headerOut.writeRawVarint32(bodyLen);
        headerOut.flush();
        
        System.out.println(ByteUtil.formatHexStr(out.array(), out.writerIndex()));
    }

}
